/**
 * Copyright (C) 2010 Cloudfarming <info@cloudfarming.nl>
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package nl.cloudfarming.client.logging;

import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.apache.commons.lang.exception.ExceptionUtils;

/**
 *
 * @author Timon Veenstra
 */
public class AppLogger extends Logger{

    public AppLogger(String name,Class clazz) {
        super(name,findName(clazz));
        setLevel(Level.ALL);
    }

    /** Finds package name for given class */
    private static String findName(Class clazz) {
        String pref = clazz.getName();
        int last = pref.lastIndexOf('.');

        if (last >= 0) {
            pref = pref.substring(0, last + 1);

            return pref + "Bundle"; // NOI18N
        } else {
            // base package, search for bundle
            return "Bundle"; // NOI18N
        }
    }

    public void info(String msg, Object... objects) {
        LogRecord record = new LogRecord(Level.INFO, msg);
        record.setResourceBundle(getResourceBundle());
        record.setParameters(objects);
        super.log(record);
    }

    public void trace(Throwable t){
        log(Level.FINE,ExceptionUtils.getStackTrace(t));
    }

    public void error(String msg, Throwable throwable) {
        log(Level.SEVERE, msg, throwable);
    }

    public void error(String msg) {
        severe(msg);
    }

    public void error(String msg, Object... objects) {
        log(Level.SEVERE, msg, objects);
    }
    
    public void warning(String msg, Object... objects) {
        log(Level.WARNING, msg, objects);
    }
}
